﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BusinessLayer;
using EntityModel;

namespace PL___Windows_Inteface
{
    public partial class SearchForm : Form
    {
        public SearchForm()
        {
            InitializeComponent();
           
        }

        private void radio_button_change(object sender, EventArgs e)
        {
            BL controller = new BL();
            info_tb.Visible = true;
            search_bt.Visible = true;
            RadioButton rb = (RadioButton)sender;
            String type = rb.Text;
            switch (type) { 
                case "Private Customer":
                    info_lb.Text = "Introduce the username of the customer:";                   
                    break;
                case "Business Customer":
                    info_lb.Text = "Introduce the username of the customer:";
                    break;
                case "Car":
                    info_lb.Text = "Introduce the Reg. Number of the car:";
                    break;
                case "Truck":
                    info_lb.Text = "Introduce the Reg. Number of the truck:";
                    break;
                case "Sell Contract":
                    info_lb.Text = "Introduce the ID of the contract:";
                    break;
                case "Lease Contract":
                    info_lb.Text = "Introduce the ID of the contract:";
                    break;
            
            }
        }      

        private void search_bt_Click(object sender, EventArgs e)
        {
              BL controller = new BL();
              if (private_rb.Checked) {
                  try
                  {
                      
                      controller.getPrivateCustomer(info_tb.Text);
                      (new ManagePrivate("VIEW", info_tb.Text)).ShowDialog();
                  }
                  catch (Exception ex) {
                      error_lb.Text = ex.Message;
                  
                  }
              }
              else if (car_rb.Checked) {
                  try
                  {

                      controller.getCar(info_tb.Text);
                      (new ManageCar("VIEW", info_tb.Text)).ShowDialog();
                  }
                  catch (Exception ex)
                  {
                      error_lb.Text = ex.Message;

                  }
              }
              else if (truck_rb.Checked)
              {
                  try
                  {

                      controller.getTruck(info_tb.Text);
                      (new ManageTrucks("VIEW", info_tb.Text)).ShowDialog();
                  }
                  catch (Exception ex)
                  {
                      error_lb.Text = ex.Message;

                  }
              }
              else if (business_rb.Checked)
              {
                  try
                  {

                      controller.getBusinessCustomer(info_tb.Text);
                      (new ManageBusiness("VIEW", info_tb.Text)).ShowDialog();
                  }
                  catch (Exception ex)
                  {
                      error_lb.Text = ex.Message;

                  }
              }
            

        }
    }
}
